<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组去重</title>
  <script>
    let arr = [1, 2, 3, 1, 2, 3, 1, 2, 3];
    Array.prototype.myFun = function () {
      let newArr = []
      arr.forEach(function (item) {
        // indexOf第一次出现的元素返回-1
        let result = newArr.indexOf(item)
        if (result === -1) {
          newArr.push(item)
        }
      })
      console.log(newArr);
    }
    arr.myFun();
  </script>
</head>

<body>

</body>

</html>